package com.cnap.multiclouldmgmt.model.enums;

import cn.hutool.core.text.CharSequenceUtil;

/**
 * 阶段类型枚举
 *
 * @author xc
 **/
public enum StageTypeEnum {
    // 初始步骤
    INIT("init", "初始步骤"),
    // 云资源开通
    CLOUD_RESOURCE("cloud", "云资源开通"),
    // 安全组端口
    SAFE_PORT("port", "安全组端口"),
    // k8s纳管
    K8S("k8s", "k8s/prometheus部署"),
    // 应用部署
    DISTRIBUTE("distribute", "应用部署"),
    // 应用部署
    END("end", "结束"),
    // 未知
    UNKNOWN("unknown", "未知");
    private final String type;
    private final String message;

    StageTypeEnum(String type, String message) {
        this.type = type;
        this.message = message;
    }

    /**
     * get
     *
     * @return Type
     */
    public String getType() {
        return type;
    }

    /**
     * get
     *
     * @return Message
     */
    public String getMessage() {
        return message;
    }


    public boolean isValid(String value) {
        if (CharSequenceUtil.isEmpty(value)) {
            return false;
        }
        StageTypeEnum[] stageTypeEnums = StageTypeEnum.values();
        for (StageTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.getType().equals(value)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获取当前枚举的前一个枚举值
     *
     * @return 结果
     */
    public StageTypeEnum previous() {
        int ordinal = this.ordinal();
        StageTypeEnum[] stageTypeEnums = StageTypeEnum.values();
        for (StageTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.ordinal() == ordinal - 1) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取当前枚举的后一个枚举值
     *
     * @return 结果
     */
    public StageTypeEnum next() {
        int ordinal = this.ordinal();
        StageTypeEnum[] stageTypeEnums = StageTypeEnum.values();
        for (StageTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.ordinal() == ordinal + 1) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }

    /**
     * 根据类型获取枚举
     *
     * @param type 类型
     * @return 结果
     */
    public static StageTypeEnum getStageTypeEnumByType(String type) {
        if (CharSequenceUtil.isEmpty(type)) {
            return UNKNOWN;
        }
        StageTypeEnum[] stageTypeEnums = StageTypeEnum.values();
        for (StageTypeEnum stageTypeEnum : stageTypeEnums) {
            if (stageTypeEnum.getType().equals(type)) {
                return stageTypeEnum;
            }
        }
        return UNKNOWN;
    }

}
